<template>
  <div class="app-container" ref="appcontainer">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px">
      <!-- <el-form-item label="表码" prop="name"> -->
      <!-- <el-select v-model="queryParams.category" placeholder="样品类型" style="width:8%;margin-right:10px">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select> -->
      
      <el-select v-if="businessType1 == 'shinei'" v-model="queryParams.project" placeholder="试验项目" style="width:8%;margin-right:10px">
        <el-option v-for="item in projectOptions" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue"></el-option>
      </el-select>

      
      <el-select v-if="businessType1 == 'shiwai'" v-model="queryParams.project" placeholder="试验项目" style="width:8%;margin-right:10px">
        <el-option v-for="item in detection_item_scene" :key="item.dictValue" :label="item.dictLabel" :value="item.dictLabel"></el-option>
      </el-select>


      <el-input v-model="queryParams.wtNumber" placeholder="委托编号" clearable size="small"
        style="width:10%;margin-right:10px" />
      <el-input v-model="queryParams.nickName" placeholder="试验人员" clearable size="small"
        style="width:8%;margin-right:10px" />
      <!-- <el-input v-model="queryParams.job" placeholder="委托单位" clearable size="small"
        style="width:10%;margin-right:10px" /> -->
      <el-input v-model="queryParams.engineeringName" placeholder="工程名称" clearable size="small"
        style="width:15%;margin-right:10px" />

      <el-date-picker
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>


      <!-- </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <!-- <el-button type="primary" size="mini" @click="handleAdd">新增</el-button> -->
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- <el-select v-model="category" @change="onCategory" placeholder="请选择检测类型" style="margin:0 0 10px 0">
      <el-option v-for="item in jiancelist" :key="item.dictValue" :label="item.dictLabel"
        :value="item.dictValue"></el-option>
    </el-select> -->

    <el-tabs v-model="businessType1" @tab-click="handleClick">
      <el-tab-pane  v-for="item in jiancelist" :key="item.dictValue" :label="item.dictLabel" :name="item.dictValue"></el-tab-pane>
    </el-tabs>


  <div v-if="businessType1 == 'shiwai'" >
    <el-table v-loading="loading" :height="tableHeight" :data="xclist" key="table02" 
      @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="业务类型" align="center">
        <template slot-scope="scope">现场</template>
      </el-table-column>
     
      <el-table-column label="委托编号" align="center" prop="wtNumber" />
      <!-- <el-table-column label="委托单位" align="center" prop="enterpriseName" /> -->
      <el-table-column label="工程名称" align="left" prop="engineeringName" width="180" />

      <el-table-column label="委托日期" align="center" prop="commissionDate" />
      <el-table-column label="试验项目" align="center" prop="testMethod" />
      <el-table-column label="检测数量" align="center" prop="testNumber" />
      <el-table-column label="项目经理" align="center" prop="businessManagerName" />
      <el-table-column label="试验人员" align="center" prop="nickName" />
      <el-table-column label="原始编号" align="center" prop="originalNumber" />
      <el-table-column label="创建日期" align="center" prop="createTime" />

      <el-table-column label="简报" align="center" prop="briefingFile">
        <template slot-scope="scope">
            <el-link
              :href="scope.row.briefingFile"
              :underline="false"
              target="_blank"
            >
              <span style="color: #1890ff">
                {{ getFileName(scope.row.briefingFile) }}
              </span>
            </el-link>
        </template>
      </el-table-column>

      <el-table-column label="数据文件" align="center" prop="dataFile">
        <template slot-scope="scope">
          <div v-for="item in scope.row.dataFileArr" :key="item" >
            <el-link
              :href="item"
              :underline="false"
              target="_blank"
            >
              <span style="color: #1890ff">
                {{ getFileName(item) }}
              </span>
            </el-link>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" width="100%" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)">修改</el-button>
        </template>
      </el-table-column>

    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
  <div v-if="businessType1 == 'shinei'">
    <el-table v-loading="loading" :height="tableHeight" :data="list" key="table01" 
      @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="业务类型" align="center">
        <template slot-scope="scope">室内</template>
      </el-table-column>

      <el-table-column label="委托编号" align="center" prop="wtNumber" />
      <el-table-column label="工程名称" align="left" prop="engineeringName" width="180" />

      <el-table-column label="委托日期" align="center" prop="commissionDate" />
      <el-table-column label="样品数" align="center" prop="sampleNumber" />
      <el-table-column label="项目经理" align="center" prop="businessManagerName" />
      <el-table-column label="试验人员" align="center" prop="chargePerson" >
        <template slot-scope="scope">
          <span>{{scope.row.userName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="检测数据" align="center" prop="projectName">
      </el-table-column>
      <el-table-column label="原始记录编号" align="center" prop="originalNumber" />
      <el-table-column label="创建日期" align="center" prop="createTime" />

      <el-table-column label="数据文件" align="center" prop="dataFile">
        <template slot-scope="scope">
          <div v-for="item in scope.row.dataFileArr" :key="item" >
            <el-link
              :href="item"
              :underline="false"
              target="_blank"
            >
              <span style="color: #1890ff">
                {{ getFileName(item) }}
              </span>
            </el-link>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" width="100%" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleUpdate1(scope.row)">修改</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>

    <!-- 新增检测报告 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="openSampleDialog" width="600px"
      append-to-body>
      <el-form ref="form" :model="form" :rules="rules" :inline="true" label-width="88px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="委托编号" prop="ipaddr">
              <el-input type="input" v-model="form.wtNumber"></el-input>
            </el-form-item>

          </el-col>
          <el-col :span="24">
            <el-form-item label="委托单位" prop="ipaddr">
              <el-select v-model="form.selectedItem" placeholder="请选择">
                <el-option v-for="item in enterpriseNamearr" :key="item.id" :label="item.name" value-key="item.id"
                  :value="item"></el-option>
              </el-select>
            </el-form-item>

          </el-col>
          <el-col :span="24">
            <el-form-item label="工程名称" prop="engineeringName">
              <el-select v-model="form.engineeringName" placeholder="请选择">
                <el-option v-for="item in engineeringOptions" :key="item.id" :label="item.name" value-key="item.id"
                  :value="item"></el-option>
              </el-select>
            </el-form-item>

          </el-col>
          <el-col :span="24">
            <el-form-item label="业务类型" prop="businessType">
              <el-select v-model="form.businessType" placeholder="请选择">
                <el-option key="shiwai" label="室外检测" value="shiwai"></el-option>
                <el-option key="shinei" label="室内检测" value="shinei"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="试验项目">
              <el-select v-model="form.project" placeholder="请选择">
                <el-option v-for="item in projectOptions" :key="item.dictValue" :label="item.dictLabel"
                  :value="item.dictValue"></el-option>
              </el-select>
            </el-form-item>

          </el-col>
          <el-col :span="24">
            <el-form-item label="总数量" prop="ipaddr">
              <el-input type="input" v-model="form.number"></el-input>
            </el-form-item>

          </el-col>
          <el-col :span="24">
            <el-form-item label="试验人员" prop="ipaddr">
              <el-select v-model="form.chargePerson" value-key="userId" placeholder="请选择">
                <el-option v-for="item in experimenter1" :value="item.userId" :key="item.userId"
                  :label="item.nickName"></el-option>
              </el-select>
            </el-form-item>

          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="完成进度" style="margin-bottom: 10px;">
              <el-input type="input" v-model="form.number"></el-input>
              <!-- <span v-html="form.reportFileName"></span> -->

            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="数据文件" style="margin-bottom: 10px;">
              <!-- <span v-html="form.reportFileName"></span> -->
              <fileUpload v-model="form.reportFile" type="jianbao"/>
            </el-form-item>
          </el-col>1

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="openSampleDialog = false">关闭</el-button>
      </div>
    </el-dialog>


    <!-- 室外项目修改 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="openUpadteDialog" width="600px"
      append-to-body>
      <el-form ref="form" :model="form" :rules="rules" :inline="true" label-width="88px">
        <el-row class="margin-bottom-10">
          <el-form-item label="委托编号">
            {{ form.wtNumber }}
          </el-form-item>

        </el-row>
        <el-row>
          <el-form-item label="委托单位">
            {{ form.enterpriseName }}
          </el-form-item>
        </el-row>

        <el-row class="margin-bottom-10">
          <el-form-item label="工程名称">
            {{ form.engineeringName }}
          </el-form-item>
        </el-row>


        <el-row class="margin-bottom-10">

          <el-form-item label="业务类型">
            {{ detection_type_arr[form.businessType] }}
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="原始编号">
            {{ form.originalNumber }}
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="检测总数">
            {{ form.testNumber }}
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="检测日期">
            {{ form.createTime }}
          </el-form-item>

        </el-row>
        <!-- <el-row>
          <el-form-item label="检测项目">
            {{ form.project }}
          </el-form-item>
        </el-row> -->
        <el-row>
          <el-form-item label="试验项目">
            {{ form.testMethod }}
          </el-form-item>
        </el-row>
        <el-row class="margin-bottom-10">
          <el-form-item label="检测数量">

            {{ form.testNumber }}

          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="拍照打卡">
            <div class="flexing">
              <div class="flex-item" v-for="item in clockinFileArray" :key="item"> 
                <img :src="item" alt="">
              </div>
              <!-- <div class="flex-item"> <img src="../../assets/images/profile.jpg" alt="" ></div> -->
            </div>

          </el-form-item>
        </el-row>
        <el-row v-if="is_show == 2"  >
          <el-col :span="24">
            <el-form-item label="简报" style="margin-bottom: 10px;">
              <fileUpload v-model="form.briefingFile" :isShowTip="false" type="dataEntry" :commonId="form.id" :businessType="form.businessType" fType="jianbao" limit="1" :chargePerson="form.jbUpdateUserId" :nickName="form.jbUpdateUserName" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="数据文件" style="margin-bottom: 10px;">
              <fileUpload v-model="form.dataFile" :isShowTip="false" type="dataEntry" :commonId="form.id" :businessType="form.businessType" fType="shuju" :chargePerson="form.updateUserId" :nickName="form.updateUserName" />
            </el-form-item>

          </el-col>

        </el-row>
        <!-- <el-row v-if="is_show == 2"  >
          <el-col :span="24">
            <el-form-item label="简报" style="margin-bottom: 10px;">
              <fileUpload v-model="form.briefingFile" type="shineiTest" :chargePerson="form.chargePerson" />
            </el-form-item>
          </el-col>
        </el-row> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">保存</el-button>
        <el-button @click="openUpadteDialog = false">关闭</el-button>
      </div>
    </el-dialog>

    <!-- 室内项目修改 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="openShineiDialog" width="800px"
      append-to-body>
      <el-form ref="form" :model="form1" :rules="rules" :inline="true">
        <el-row class="margin-bottom-10">
          <el-form-item label="委托编号" style="width:300px;">
            {{ form1.wtNumber }}
          </el-form-item>
          <!-- <el-form-item label="委托单位">
            {{ form1.enterpriseName }}
          </el-form-item> -->
        </el-row>

        <el-row class="margin-bottom-10">
          <el-form-item label="工程名称">
            {{ form1.engineeringName }}
          </el-form-item>
        </el-row>


        <!-- <el-row class="margin-bottom-10">
          <el-form-item label="业务类型" style="width:300px;">
        
          </el-form-item>
        </el-row> -->
        <el-row class="margin-bottom-10">
          <el-form-item label="试验项目">
            {{ form1.projectName }}
          </el-form-item>
        </el-row>
        <el-row class="margin-bottom-10">
          <el-form-item label="总数量">
            {{ form1.number }}
          </el-form-item>
        </el-row>
        <el-row class="margin-bottom-10">
          <el-form-item label="试验人员">
            {{ form1.userName }}
          </el-form-item>
        </el-row>
        <el-row class="margin-bottom-10">
          <el-form-item label="完成进度">
            {{ form1.number }}/{{form1.sampleNumber	}}
          </el-form-item>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="数据文件" style="margin-bottom: 10px;">
              <!-- <span v-html="form.reportFileName"></span> -->
              <fileUpload v-model="form1.dataFile" type="dataEntry" :commonId="form1.id" :businessType="form1.businessType" fType="shuju" :chargePerson="form1.updateUserId" :nickName="form1.updateUserName" />
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm1">保存</el-button>
        <el-button @click="openShineiDialog = false">关闭</el-button>
      </div>
    </el-dialog>


    <!-- 数据（室外） -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="openShiwaiDialog" width="800px"
      append-to-body>
      <el-form ref="form" :model="form" :rules="rules" :inline="true">
        <el-row class="margin-bottom-10">
          <el-form-item label="委托编号" style="width:250px;">
            {{ form.gsNumber }}
          </el-form-item>
          <el-form-item label="委托单位">
            {{ form.enterpriseName }}
          </el-form-item>
        </el-row>

        <el-row class="margin-bottom-10">
          <el-form-item label="工程名称">
            {{ form.engineeringName }}
          </el-form-item>
        </el-row>


        <el-row class="margin-bottom-10">
          <el-form-item label="试验项目" style="width:300px;">
            {{ form.project }}
          </el-form-item>
          <el-form-item label="总数量">
            {{ form.sampleNumber }}
          </el-form-item>
        </el-row>

        <el-row class="margin-bottom-10">
          <el-form-item label="试验人员" style="width:300px;">
            {{ form.chargePerson }}
          </el-form-item>
          <el-form-item label="完成进度">
            {{ form.doingSum }}/{{ form.sampleNumber }}
          </el-form-item>
        </el-row>

        <!-- <el-row class="margin-bottom-10">
          <el-form-item label="数据文件"  >
            {{form.chargePerson}}
          </el-form-item>
        </el-row> -->

        <el-row class="margin-bottom-10">
          <el-form-item label="报告文件">
            <a style="color: #1890ff;" :href="form.reportFile" :download="form.reportFileName">{{ form.reportFileName
            }}</a>
          </el-form-item>
        </el-row>

        <el-row class="margin-bottom-10">
          <el-form-item label="试验录入">
            <el-card v-for="item in form.attachedRecordList" :key="item.id" class="box-card"
              style="width:200px;margin-bottom:10px;">
              <div slot="header" class="clearfix">
                <span>{{ form.project }}</span>
              </div>
              <div class="text item">
                检测日期：{{ item.startTime }}
              </div>
              <div class="text item">
                检测数量：{{ item.testNumber }}
              </div>
              <div class="text item">
                <!-- 试验人员：{{item.userName}} -->
              </div>
            </el-card>

          </el-form-item>

        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">保存</el-button> -->
        <el-button @click="cancel3(openShiwaiDialog = false)">关闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  geteditEnterprise,
  listEnterpriseAll,
  searchProject,
  getAttachedDatadetail

} from "@/api/enterprise/enterprise";
import { getToken } from "@/utils/auth";
import { listSampleAll, getSampleRecord, getAttachedRecord, getAttachedRecord1, getSampleRecorddantiao, updateSampleRecord, updateSampleRecord2 } from "@/api/sample/sample";
import { listInstrumentAll } from "@/api/instrument/instrument";
import { listAttachedDataAll } from "@/api/attachedData/attachedData";
import { getReport, addReport, updateReport, delReport, createReportNumber } from "@/api/report/report";
import Cookies from "js-cookie";
import {
  listAllUser
} from "@/api/system/user.js";
import orderDialog from "./components/orderFallin";
import acceptDialog from "./components/orderAccept";
export default {
  components: { orderDialog, acceptDialog },
  name: "Enterprise",
  data() {
    return {
      // 日期范围
      dateRange: [],
      fileList: [],
      enterpriseNamearr: [],
      shineiid: '',
      shiwaiid: '',
      category: 'shinei',
      headers: { Authorization: "Bearer " + getToken() },
      uploadUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
      uploadDelete: false,
      jiancelist: [],
      projectOptions: [],

      detection_type: [],
      detection_type_arr:[],
      instrumentList: [],//所有仪器
      detection_item_indoor: [],//字典：室内检测项目
      detection_item_scene: [],//字典：室外检测项目
      commissionListAll: [],//所有工程
      shiyanQuery: {
        commissionId: 0
      },//试验项目搜索条件
      shiyanList: [],//所有试验项目
      form: {},
      form1: {},

      xclist: [],
      detectionOptions: [],
      openSampleDialog: false,
      openUpadteDialog: false,
      openShineiDialog: false,
      openShiwaiDialog: false,
      tableHeight: 0,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      clockinFileArray: [],
      // 企业信息表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      openDialog: false,
      openAcceptDialog: false,
      // 企业类型字典
      typeOptions: [],
      // 状态 1=开业，2=停业字典
      statusOptions: [],
      options: [
        {
          label: "11",
          value: "11"
        }
      ],
      engineeringOptions: [],
      experimenter1: [],
      businessType1: 'shiwai',
      businessType: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // reportNumber: '',
        // chargePerson: '',
        // enterpriseName: '',
        // engineeringName: '',
        // startCreateTime: '',
        // category: '',
        // project: '',
      },
      // 表单参数
      form: {
        // pageNum: 1,
        reportDate: "2025-05-18",
        grantDate: "2025-05-18",
        sampleOne: {},
        sampleRecordList: [],
        attachedDataOne: {},
        attachedRecordList: [

        ],
      },
      // 表单校验
      rules: {
        commissionId: [
          { required: true, message: "请选择委托单", trigger: "blur" }
        ],
        commonId: [
          { required: true, message: "请选择试验项目", trigger: "blur" }
        ],

        reportNumber: [
          { required: true, message: "报告编号不能为空", trigger: "blur" }
        ],
        testNum: [
          { required: true, message: "检测数量不能为空", trigger: "blur" }
        ],
        reportFile: [
          { required: true, message: "请上传文件", trigger: "blur" }
        ],
        grantNum: [
          { required: true, message: "发放日期不能为空", trigger: "blur" }
        ],

      },

      //创建报告编号搜索
      createReportQuery: {
        commissionId: "",
        project: '',
        businessType: '',
      },

      roleId: null,
      roles: [],
      enterpriseId: null,
      is_show:2,//1=不显示，2=显示
    };
  },
  created() {
    //当前用户的信息
    let userInfo = JSON.parse(Cookies.get("userinfo"));
    this.roles = userInfo.roles
    this.roleId = userInfo.roleId
    this.enterpriseId = userInfo.enterpriseId

    for(let i=0; i < this.roles.length;i++){
      if(this.roles[i].roleId == 7 ){
        this.is_show = 1
      }
    }

    this.listInstrumentAll();//所有仪器

    this.getgclist()
    this.getProject()
    this.getUser()

    this.calHeight();

    //检测类型
    this.getDicts("detection_type").then(response => {
      this.jiancelist = response.data
      let data = response.data
      let new_arr = [];
      data.forEach(function (item) {
        new_arr[item.dictValue] = item.dictLabel
      });
      this.detection_type_arr = new_arr;
    });

    //室内字典
    this.getDicts("detection_item_indoor").then(response => {
      this.projectOptions = response.data
      let data = response.data
      let new_arr = [];
      data.forEach(function (item) {
        new_arr[item.dictValue] = item.dictLabel
      });
      this.detection_item_indoor = new_arr;
    });

    //室外字典 detection_item_scene
    this.getDicts("detection_item_scene").then(response => {
      this.detection_item_scene = response.data
      
    });

    this.getList();
    // this.getxcList();

  },
  watch: {
    showSearch: "calHeight"
  },
  methods: {
    getUser() {
      listAllUser({ roleId: 5 }).then(res => {
        this.experimenter1 = res.data
      })
    },
    //工程信息查询所有
    getProject() {
      searchProject(this.engineeringSearch).then((res) => {
        this.engineeringOptions = res.data;
      })
    },

    //企业信息查询所有
    getgclist() {
      listEnterpriseAll().then((res) => {
        this.enterpriseNamearr = res.data;
      });
    },
    onCategory(val) {
      console.log(val)
      if (val == 'shiwai') {
        this.getxcList()
      } else {
        this.getList()
      }
      this.businessType1 = val
    },
    
    handleClick(tab, event) {
      this.businessType1 = tab.name
      this.queryParams.pageNum = 1;
      this.getList()
    },
    //现场检测列表
    // getxcList() {
    //   this.loading = true;
    //   this.queryParams.isRoleShow = 1
      
    // },
    /** 室内列表 */
    getList() {
      this.loading = true;
      this.queryParams.isRoleShow = 1
      if(this.businessType1=="shiwai"){
        getAttachedRecord(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          let data = response.rows
          data.forEach(function(item){
            if(item.dataFile){
              item.dataFileArr = item.dataFile.split(",");
            }else{
              item.dataFileArr = [];
            }
          })
          this.xclist = data;
          this.total = response.total;
          this.loading = false;
        });
      }else{
        getSampleRecord(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          let data = response.rows;
          data.forEach(function(item){
            if(item.dataFile){
              item.dataFileArr = item.dataFile.split(",");
            }else{
              item.dataFileArr = [];
            }
          })
          console.log("dgggg");
          console.log(data)
          this.list = data;
          this.total = response.total;
          this.loading = false;
        });
      }

    },


    closeAcceptDialog() {
      this.openAcceptDialog = false;
    },
    calHeight() {
      this.$nextTick(() => {
        const rect = this.$refs.appcontainer.getBoundingClientRect();
        let height = this.$refs.queryForm.$el.offsetHeight;
        this.tableHeight = rect.height - height - 120;
      });
    },


    listInstrumentAll() {
      listInstrumentAll().then(response => {
        let data = response.data
        data.forEach(function (item) {
          item.label = "(编号：" + item.instrumentNumber + ")委托单位：" + item.instrumentName
        });
        this.instrumentList = data;
      });
    },


    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },


    // 表单重置
    reset() {
      this.form = {}
      this.isShowcreateReport = false
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.showSearch = false;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleAccept(row) {
      this.openAcceptDialog = true;
      this.title = "委托单受理";
    },
    handleCollar() { },
    handleReport() { },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
      }
      this.dateRange = [];
      this.resetForm("queryParams");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      if (this.businessType1 == 'shinei') {
        this.openSampleDialog = true;
        this.title = "添加试验数据(室内)";
      } else {
        this.$message.warning(`请选择项目类别`)
      }

    },
    //修改室内项目
    handleUpdate1(row) {
      this.shineiid = row.id
      const id = row.id;
      getSampleRecorddantiao(id).then(res => {
        this.form1 = res.data
        this.openShineiDialog = true
      })
      this.title = "室内检测数据";

    },
    /** 修改室外按钮操作 */
    handleUpdate(row) {
      this.shiwaiid = row.id
      // this.reset();
      const id = row.id;
      getAttachedRecord1(id).then(res => {
        if (res.data.clockinFile !== '' || res.data.clockinFile != null) {
          this.clockinFileArray =
            (res.data.clockinFile || '').split(',').filter(Boolean).map(item => item.trim());
        }
        console.log(this.clockinFileArray, 'clockinFileArray')
        this.form = res.data;
        this.openUpadteDialog = true;
        this.title = "现场检测数据";
      })
      // getAttachedDatadetail(id).then(response => {
      //   this.form = response.data;
      //   this.openUpadteDialog = true;
      //   this.title = "修改报告";
      // });
    },
    // 数据
    handleData(row) {
      let _this = this
      this.reset();
      const id = row.id;

    },
    //室内项目修改
    submitForm1() {
      let obj = {
        id: this.shineiid,
        dataFile: this.form1.dataFile,
      }
      updateSampleRecord2(obj).then(res => {
        this.getList()
        this.$message.success(res.msg)
        this.openShineiDialog = false
      })
    },
    //室外项目修改提交
    submitForm2() {
      let obj = {
        id: this.shiwaiid,
        dataFile: this.form.dataFile,
        briefingFile: this.form.briefingFile
      }
      updateSampleRecord(obj).then(res => {
        this.getList()
        this.$message.success(res.msg)
        this.openUpadteDialog = false
      })
    },
    /** 提交按钮 */
    submitForm() {


    },
    sendNotice(data, project) {
      let params = data.data;
      let noticContent = params.engineeringName + "的委托单" + params.number + project + "检测报告已上传!";
      let notice = {
        "userId": params.name,
        "noticType": "报告上传",
        "noticContent": noticContent,
        "commissionId": params.id,
        "engineeringId": params.engineeringId
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm("是否确认删除?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function () {
          return logicDelEnterprise(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有企业信息数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.exportLoading = true;
          return exportEnterprise(queryParams);
        })
        .then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => { });
    },
    // 上传前校检格式和大小
    handleBeforeUpload(file) {
      // 校检文件大小
      if (this.fileSize) {
        const isLt = file.size / 1024 / 1024 < this.fileSize;
        if (!isLt) {
          this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`);
          return false;
        }
      }
      return true;
    },
    handleUploadSuccess(res, file) {
      this.form.reportFile = res.fileName2
      this.form.reportFileName = res.originalFilename
    },

    // 获取文件名称
    getFileName(name) {
      if (name) {
        if (name.lastIndexOf("/") > -1) {
          return name.slice(name.lastIndexOf("/") + 1).toLowerCase();
        } else {
          return "";
        }
      } else {
        return "";
      }
    },
  }
};
</script>
<style>
.flexing {
  display: flex;
  justify-content: flex-start;
  align-self: center;
}

.flex-item img {
  width: 80px;
  height: 80px;
  flex: 1;
  margin-right: 9px;
}
</style>
